﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Touch2Like.Model;
using Touch2Like.SharedLibrary;

namespace Touch2Like.Web.Customer
{
    public partial class changepassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["t"]))
            {
                Touch2Like.DAL.UserDAL user = new Touch2Like.DAL.UserDAL();
                UserInfo info = user.GetUserByNameAndEmail(0,Request["u"].Trim());

                if (info != null && Request["t"].Trim() == Utility.Encryption.Encrypt(Request["u"].Trim()))
                {
                    lb_UserName.Text = info.UserName;
                    lb_Email.Text = info.Email;
                }
            }
        }

        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["t"]))
            {
                Touch2Like.DAL.UserDAL user = new Touch2Like.DAL.UserDAL();
                UserInfo info = user.GetUserByNameAndEmail(0,Request["u"].Trim());

                if (info != null && Request["t"].Trim() == Utility.Encryption.Encrypt(Request["u"].Trim()))
                {
                    info.Password = Utility.Encryption.Encrypt(tb_Password.Text);

                    user.UpdateUser(info,"UPDATE");

                    Response.Redirect("/Customer/signin.aspx");
                }
            }
        }
    }
}